package org.library.menu;

import org.library.controller.TokenController;
import org.library.domain.LoginUser;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.stereotype.Component;

/**
 * @author Chen
 * @since 2023/6/13 15:06
 */

@Component
public class LoginMenu extends Menu {

    public LoginMenu(BeanFactory beanFactory) {
        super(beanFactory);
    }

    @Override
    public void menu() {
        System.out.println("欢迎登录图书管理系统");
        System.out.println("请输入手机号：");
        String username = scanner.next();
        System.out.println("请输入密码：");
        String password = scanner.next();
        LoginUser loginUser = controllerFactory.getController(TokenController.class).login(username, password);
        if (loginUser == null) {
            System.out.println("用户名或密码错误");
            library.setMenu(beanFactory.getBean(MainMenu.class));
        } else {
            library.setLoginUser(loginUser);
            library.setMenu(beanFactory.getBean(UserMenu.class));
        }
        library.run();
    }
}
